﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Iesi.Collections;

namespace MSH.Common.Business
{
    /// <summary>
    /// Business object voor een gebruiker
    /// </summary>
    public class User
    {
        private Int32 _id;
        private String _username;
        private String _password;
        private String _status;
        private Boolean _activated;
        private DateTime? _lastSeenTimestamp;
        private DateTime? _registeredTimestamp;
        private Int32 _activationRequestCount;

        //Associations
        private UserProfile _userProfile;
        private UserActivation _userActivation;
        private ISet _userLocations = new HashedSet();
        private UserLocation _lastUserLocation;
        private ISet _userFriends = new HashedSet();
        private ISet _chatMessages = new HashedSet();
        private ISet _userSocialNetworkAccounts = new HashedSet();
        private ISet _userSocialNetworkProfileData = new HashedSet();
        private UserSettings _userSettings;

        /// <summary>
        /// Database id
        /// </summary>
        public virtual Int32 ID
        {
            get { return _id; }
            set { _id = value; }
        }

        /// <summary>
        /// De gebruikersnaam
        /// </summary>
        public virtual String Username
        {
            get { return _username; }
            set { _username = value; }
        }

        /// <summary>
        /// Het wachtwoord in MD5Hash
        /// </summary>
        public virtual String Password
        {
            get { return _password; }
            set { _password = value; }
        }

        /// <summary>
        /// Status van de gebruiker
        /// </summary>
        public virtual String Status
        {
            get { return _status; }
            set { _status = value; }
        }

        /// <summary>
        /// Boolean of het account al geactiveerd is
        /// </summary>
        public virtual Boolean Activated
        {
            get { return _activated; }
            set { _activated = value; }
        }

        /// <summary>
        /// Datum en tijd van wanneer de gebruiker voor het laats gezien is
        /// </summary>
        public virtual DateTime? LastSeenTimestamp
        {
            get { return _lastSeenTimestamp; }
            set { _lastSeenTimestamp = value; }
        }

        /// <summary>
        /// Datum en tijd wanneer de gebruiker geregistreerd is
        /// </summary>
        public virtual DateTime? RegisteredTimestamp
        {
            get { return _registeredTimestamp; }
            set { _registeredTimestamp = value; }
        }

        /// <summary>
        /// Aantal keer dat de activatiecode verstuurd is
        /// </summary>
        public virtual Int32 ActivationRequestCount
        {
            get { return _activationRequestCount; }
            set { _activationRequestCount = value; }
        }

        /// <summary>
        /// Het gekoppelde gebruikersprofiel
        /// </summary>
        public virtual UserProfile UserProfile
        {
            get { return _userProfile; }
            set { _userProfile = value; }
        }

        /// <summary>
        /// De gekoppelde activatie code
        /// </summary>
        public virtual UserActivation UserActivation
        {
            get { return _userActivation; }
            set { _userActivation = value; }
        }

        /// <summary>
        /// De laatste 10 locaties van de gebruiker
        /// </summary>
        public virtual ISet UserLocations
        {
            get { return _userLocations; }
            set { _userLocations = value; }
        }

        /// <summary>
        /// De laatst gemelde locatie van de gebruiker
        /// </summary>
        public virtual UserLocation LastUserLocation
        {
            get { return _lastUserLocation; }
            set 
            { 
                _lastUserLocation = value;
                if(value != null)
                    UserLocations.Add(_lastUserLocation);
            }
        }

        /// <summary>
        /// Lijst met MSH vrienden
        /// </summary>
        public virtual ISet UserFriends
        {
            get { return _userFriends; }
            set { _userFriends = value; }
        }

        /// <summary>
        /// Lijst van binnenkomende chat berichten
        /// </summary>
        public virtual ISet ChatMessages
        {
            get { return _chatMessages; }
            set { _chatMessages = value; }
        }

        /// <summary>
        /// Lijst van gekoppelde sociale netwerken
        /// </summary>
        public virtual ISet UserSocialNetworkAccounts
        {
            get { return _userSocialNetworkAccounts; }
            set { _userSocialNetworkAccounts = value; }
        }

        /// <summary>
        /// Lijst met profiel data uit de gekoppelde sociale netwerken
        /// </summary>
        public virtual ISet UserSocialNetworkProfileData
        {
            get { return _userSocialNetworkProfileData; }
            set { _userSocialNetworkProfileData = value; }
        }


        

        public virtual UserSettings UserSettings
        {
            get { return _userSettings; }
            set { _userSettings = value; }
        }

        public virtual String GetFullName()
        {
            if (UserProfile != null && (!String.IsNullOrEmpty(UserProfile.FirstName) || !String.IsNullOrEmpty(UserProfile.SurName)))
            {
                return (UserProfile.FirstName + " " + UserProfile.SurName).Trim();
            }
            return Username;
        }
    }
}
